home *** CD-ROM | disk | FTP | other *** search
- Function CopyFile% (InFile$, OutFile$, ErrorNbr%)
-
- 'Parameters ************************************************************
- ' Input values:
- ' InFile$ The name of the file to copy
- ' OutFile$ The new file to create
- ' Output value:
- ' ErrorNbr% Zero if no error, otherwise the VB error number
-
- 'The function returns True (-1) if the file was successfully copied.
- 'Otherwise the function returns False (0), and places the error number
- 'into the ErrorNbr% parameter
- '***********************************************************************
-
- On Error GoTo ErrorCopyingFile
- BufferLen& = 28 * 1024& 'Set to a large string length
-
- ' Open files
-
- InFileNbr% = FreeFile 'Get next available file number
- Open InFile$ For Binary Access Read Lock Read Write As InFileNbr%
-
- OutFileNbr% = FreeFile 'Get next available file number
- Open OutFile$ For Binary Access Write Lock Read Write As OutFileNbr%
-
- ' Establish buffer length
-
- InFileLen& = LOF(InFileNbr%)
- If InFileLen& < BufferLen& Then
- BufferLen& = InFileLen&
- End If
- Buffer$ = Space$(BufferLen&) 'Initialize buffer
-
- Do 'Copy as much of file as possible in large blocks
- Get #InFileNbr%, , Buffer$
- Put #OutFileNbr%, , Buffer$
- Loop While (Not EOF(InFileNbr%)) And (InFileLen& >= (Loc(InFileNbr%) + BufferLen&))
-
- If Not EOF(InFileNbr%) Then ' Copy rest of file if any
- Buffer$ = Space$(InFileLen& - Loc(InFileNbr%))
- Get #InFileNbr%, , Buffer$
- Put #OutFileNbr%, , Buffer$
- End If
-
- CopyFile% = -1 ' Function ended successfully
- ErrorNbr% = 0 ' No error number to return
-
- LeaveFunction:
- Close #InFileNbr%, OutFileNbr%
- Exit Function
-
- ErrorCopyingFile:
- CopyFile% = 0 'Return value that indicates function error
- ErrorNbr% = Err 'Return specific error code
- Resume LeaveFunction
- End Function